﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace HW0225_2
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            this.InitializeComponent();
            this.Init();
        }

        private void Init()
        {
            this.AutoSizeMode = AutoSizeMode.GrowAndShrink;
            this.AutoSize = false;
            this.MaximizeBox = false;
            this.MinimizeBox = false;
        }

        private void Form1_Load(object sender, EventArgs e)
        {
        }

        private void tb_min_TextChanged(object sender, EventArgs e)
        {
        
        }

        private void tb_max_TextChanged(object sender, EventArgs e)
        {

        }

        private void button1_Click(object sender, EventArgs e)
        {
            try
            {
                tb_result.Text = null; //初始化输入框
                int a = Convert.ToInt32(tb_max.Text);
                int b = Convert.ToInt32(tb_min.Text);
                int count = 0;//计数器，控制10个一行输出
                if (a <= b || a < 0 || b < 0)
                {
                    tb_result.Text = "请输入正确的大于0的上限和下限！";
                    return;
                }
                else
                {
                    for (int i = b; i <= a; i++)
                    {
                        int y = Calc(i);
                        if (y == -1)
                        {
                            continue;
                        }
                        else
                        {
                            tb_result.AppendText(y.ToString() + " ");
                            if (y < 10)
                            {
                                tb_result.AppendText(" ");
                            }
                            count++;
                            if (count == 10)
                            {
                                count = 0;
                                tb_result.AppendText("\r\n");
                            }
                        }
                    }
                }
            }
            catch (System.FormatException)
            {
                this.tb_result.Text = ("请输入正确的数字！");
            }
        }
        
        private int Calc(int x)
        {
            if((x % 2 ==0 || x % 3 ==0 || x % 5 == 0 || x % 7 == 0) && (x != 1 && x != 2 && x != 3 && x != 5 && x != 7))
            {
                x = -1;
                return x;//如果x=-1则说明不是负数，返回上面的方法，跳过该数的输出
            }
            else
            {
                return x;
            }
        }
    }
}
